//
//  WQ_visitorsV.swift
//  xinlang
//
//  Created by 联创—王增辉 on 2019/3/20.
//  Copyright © 2019年 lcWorld. All rights reserved.
//

import UIKit

class WQ_visitorsV: UIView {
    
    lazy var visitordiscoverImageV = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    lazy var maskImageV = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    lazy var iconImageV = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    lazy var titleL = { () -> UILabel in
    let lable = UILabel.init()
        lable.numberOfLines = 0;
        lable.textAlignment = .center
        return lable
    }()
    lazy var registerBtn = { () -> UIButton in
        let button = UIButton()
        button.setTitle("注册", for: .normal)
        button.setBackgroundImage(UIImage.init(named: "common_button_white_disable"), for: .normal)
        button.setTitleColor(UIColor.orange, for: .normal)
        button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 9, bottom: 5, right: 9)

        return button
    }()
    lazy var loginBtn =  { () -> UIButton in
        let button = UIButton()
        button.setTitle("登录", for: .normal)
        button.setBackgroundImage(UIImage.init(named: "common_button_white_disable"), for: .normal)
        button.setTitleColor(UIColor.black, for: .normal)
        button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 9, bottom: 5, right: 9)
        return button
    }()
    var visitor:[String:String]?{
        didSet{
            if visitor?["icon"] == "" {
                setAnimaTion()
                return
            }
            iconImageV.image = UIImage(named: visitor?["icon"] ?? "")
            visitordiscoverImageV.isHidden = true
            maskImageV.isHidden = true
            if let titleStr = visitor?["title"] {
                titleL.text = titleStr
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.Hex(colorHex: 0xededed)
        setupUI()
        titleL.text = "吃的话吃的话吃的话吃的话吃的话吃的话吃的话吃的话吃的话"
        
    }
    func setAnimaTion()  {
        let animation = CABasicAnimation(keyPath: nil)
        animation.toValue = 2 * Double.pi
        animation.duration = 15
        animation.repeatCount = MAXFLOAT
        animation.isRemovedOnCompletion = false
        visitordiscoverImageV.layer .add(animation, forKey: "transform.rotation")
    }
    func setupUI() {
        
        addSubview(visitordiscoverImageV)
        addSubview(maskImageV)
        addSubview(iconImageV)
        addSubview(titleL)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        for item in subviews {
            item.translatesAutoresizingMaskIntoConstraints = false
        }
        //房子
        addConstraint(NSLayoutConstraint(item: iconImageV, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: iconImageV, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: -60))

        //圆形图
        addConstraint(NSLayoutConstraint(item: visitordiscoverImageV, attribute: .centerX, relatedBy: .equal, toItem: iconImageV, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: visitordiscoverImageV, attribute: .centerY, relatedBy: .equal, toItem: iconImageV, attribute: .centerY, multiplier: 1.0, constant: 0))
        
        //遮罩
        addConstraint(NSLayoutConstraint(item: maskImageV, attribute: .centerX, relatedBy: .equal, toItem: iconImageV, attribute: .centerX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: maskImageV, attribute: .centerY, relatedBy: .equal, toItem: iconImageV, attribute: .centerY, multiplier: 1.0, constant: 0))
        //文字简介
        addConstraint(NSLayoutConstraint(item: titleL, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 256))
        addConstraint(NSLayoutConstraint(item: titleL, attribute: .top, relatedBy: .equal, toItem: iconImageV, attribute: .bottom, multiplier: 1.0, constant: 60))
        addConstraint(NSLayoutConstraint(item: titleL, attribute: .centerX, relatedBy: .equal, toItem: iconImageV, attribute: .centerX, multiplier: 1.0, constant: 0))
        //注册
        addConstraint(NSLayoutConstraint(item: registerBtn, attribute: .left, relatedBy: .equal, toItem: titleL, attribute: .left, multiplier: 1.0, constant: 10))
        addConstraint(NSLayoutConstraint(item: registerBtn, attribute: .top, relatedBy: .equal, toItem: titleL, attribute: .bottom, multiplier: 1.0, constant: 10))
        //登录
        addConstraint(NSLayoutConstraint(item: loginBtn, attribute: .right, relatedBy: .equal, toItem: titleL, attribute: .right, multiplier: 1.0, constant: 10))
        addConstraint(NSLayoutConstraint(item: loginBtn, attribute: .top, relatedBy: .equal, toItem: titleL, attribute: .bottom, multiplier: 1.0, constant: 10))

    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
